package com.qk.management.controller;

import com.qk.common.PageResult;
import com.qk.common.Result;
import com.qk.domain.customer.CustomerDO;
import com.qk.dto.customer.CustomerAddDTO;
import com.qk.dto.customer.CustomerDTO;
import com.qk.dto.customer.CustomerUpdateDTO;
import com.qk.entity.Customer;
import com.qk.management.aop.anno.LogAnno;
import com.qk.management.service.CustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * @Author ZgYn
 * @Date 2025/10/16 16:13
 * @Name CustomerController
 */
@RestController
@RequestMapping("/customers")
public class CustomerController {
    @Autowired
    private CustomerService customerService;

    @GetMapping
    public Result getCustomers(CustomerDTO dto) {
        PageResult<CustomerDO> pageResult = customerService.selectList(dto);
        return Result.success(pageResult);
    }

    @LogAnno
    @PostMapping
    public Result addCustomer(@RequestBody CustomerAddDTO dto) {
        customerService.addCustomer(dto);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result getCustomerById(@PathVariable Long id) {
        Customer customer = customerService.getById(id);
        return Result.success(customer);
    }

    @LogAnno
    @PutMapping
    public Result updateCustomer(@RequestBody CustomerUpdateDTO dto) {
        customerService.updateCustomer(dto);
        return Result.success();
    }
}
